package com.qianfeng.listviewdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.List;


/**
 * Created by jackiechan on 16/3/11 上午11:42.
 * 版本: 1
 * 公司:北京千锋互联科技有限公司
 */
public class MyAdaper2 extends BaseAdapter implements View.OnClickListener {
    private List<Bean> lists;
    private Context context;

    public MyAdaper2(Context context, List<Bean> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists==null?0:lists.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Bean bean = lists.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item, null);
        }
        CheckBox che = (CheckBox) convertView.findViewById(R.id.check);
        TextView t = (TextView) convertView.findViewById(R.id.tv);
//        if (bean.isCheck()) {
//            che.setChecked(true);
//        }
        che.setChecked(bean.isCheck());//设置选择状态
        t.setText("这是第几" + position);
        che.setTag(position);
        che.setOnClickListener(this);
        return convertView;
    }

    @Override
    public void onClick(View v) {
        int tag = (int) v.getTag();
        lists.get(tag).setIsCheck(((CheckBox) v).isChecked());//修改数据源
    }
}
